package 二叉搜索树的最近公共祖先;

/**
 * @author AirMan
 * @version 1.0
 * @description 二叉搜索树的最近公共祖先测试
 * @date 2025/4/7 10:04
 */
public class Test {
    public static void main(String[] args) {
        // Create a sample binary search tree
        TreeNode root = new TreeNode(6);
        root.left = new TreeNode(2);
        root.right = new TreeNode(8);
        root.left.left = new TreeNode(0);
        root.left.right = new TreeNode(4);
        root.right.left = new TreeNode(7);
        root.right.right = new TreeNode(9);
        root.left.right.left = new TreeNode(3);
        root.left.right.right = new TreeNode(5);

        // Test the lowestCommonAncestor method
        TreeNode p = root.left; // Node with value 2
        TreeNode q = root.left.right; // Node with value 4
        Solution solution = new Solution();
        TreeNode lca = solution.lowestCommonAncestor(root, p, q);
        System.out.println("Lowest Common Ancestor of " + p.val + " and " + q.val + " is " + lca.val);
    }
}
